package com.ushine.web.base.controller;

import com.ushine.web.base.model.system.DataPermissionDO;
import com.ushine.web.base.service.IDataPermissionService;
import com.ushine.web.component.http.HttpResponseVO;
import com.ushine.web.log.annotation.SystemControllerLog;
import com.ushine.web.log.constant.LogConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: yls
 * @Date: 2022/02/16 00:08
 * @Description: 数据权限控制器
 * @Version 1.0
 */
@RestController
@Api(tags = "基础模块-数据权限")
@RequestMapping("system/dataPermission")
@Validated
public class DataPermissionController {

    @Resource
    private IDataPermissionService dataPermissionService;

    @SystemControllerLog(operation = LogConstant.CREATE)
    @ApiOperation(value = "添加数据权限")
    @PostMapping("insertPermission")
    @ResponseStatus(HttpStatus.OK)
    public HttpResponseVO<Object> insertPermission(@ApiParam(value = "数据权限实体", required = true) @RequestBody DataPermissionDO dataPermission) {
        Boolean flag = dataPermissionService.insertDataPermission(dataPermission);
        if (Boolean.TRUE.equals(flag)) {
            return new HttpResponseVO<>().ok("添加成功！");
        } else {
            return new HttpResponseVO<>().error("添加失败！");
        }
    }

    @SystemControllerLog(operation = LogConstant.READ)
    @ApiOperation(value = "查询数据权限")
    @GetMapping("listAllPermissions")
    public HttpResponseVO<List<DataPermissionDO>> listAllPermissions() {
        List<DataPermissionDO> dataPermissionList = dataPermissionService.listAllDataPermissions();
        return new HttpResponseVO<List<DataPermissionDO>>().ok("", dataPermissionList);
    }
}
